// Time Tracker by Eric Nadeau (nado18@gmail.com)
// Copyright (C) 2007 by Eric Nadeau
// Distributed under the terms of the GNU General Public License (see GPL.txt)

package tests;

import model.*;
import junit.framework.*;

/**
 * @author Eric Nadeau (nado18@gmail.com), on Apr 21, 2004
 */
public class ProjectTest extends TestCase {
	private Project p;
	
	public ProjectTest(String arg0) {
		super(arg0);
	}
	
	public void setUp() {
		p = new Project();
		p.setElapsed( (37*60+28)*60+17 );
		p.setInitial(250);
		p.setRate(20);
		p.setName("Testing Project");
	}

	public void testGetBillTime() {
		Assert.assertEquals(
			"37:28:17",
			p.getBillTime()
		);
	}

	public void testGetBillPrice() {
		double p1 = 999.43; // 37:28:17 at 20$/hour + 250$ initial
		double p2 = Double.parseDouble( p.getBillPrice() );
		
		Assert.assertEquals(p1, p2, 0.01);
		Assert.assertEquals("999.43", p.getBillPrice());
	}
	
	public synchronized void testTimer() {
		try {
			p.start();
			wait(2000);
			p.stop();
			
			double p1 = 999.44;
			double p2 = Double.parseDouble( p.getBillPrice() );

			Assert.assertEquals(p1, p2, 0.01);
		}
		catch (InterruptedException e) {
			Assert.fail();
		}
	}

}
